import top.malaoshi.data.DataColumn;
import top.malaoshi.data.DataQuery;
import top.malaoshi.data.DataRow;
import top.malaoshi.data.DataTable;
import top.malaoshi.util.Out;

/**
 * 加载歧义词库
 */
public class S5查询_测试select {
    static DataTable ready(){
        DataTable dt = new DataTable("t_user");
        Out.println("表名：",dt.getName());

        dt.columns().add("id");
        dt.columns().add("username", DataColumn.Type.TEXT);
        dt.columns().add("password", DataColumn.Type.TEXT);
        dt.columns().add("age", DataColumn.Type.INT);
        dt.columns().add("height", DataColumn.Type.DOUBLE);
        dt.columns().add("birthday", DataColumn.Type.TEXT);

        dt.rows().add(new Object[]{1,"lilei","123456",20,1.83,"2000-06-01"});
        DataRow drHmm = dt.rows().add(new Object[]{2, "韩梅梅", "666", 22,1.65,"2000-07-01"});

        // 创建 DataRnow
        DataRow dataRow = dt.newRow();
        dt.rows().add(dataRow);
//        通过索引设置数据
        dataRow.setValue( 0,3 );
        dataRow.setValue( 1,"lucy" );
        dataRow.setValue( 2,"333" );
        dataRow.setValue( 3,22);
        dataRow.setValue( 4,1.73 );
        dataRow.setValue( 5,"2000-08-01" );

        // 创建 DataRnow
        DataRow dataRow2 = dt.newRow();

        drHmm.setValue("id",4);
        drHmm.setValue("username","lili");
        drHmm.setValue("password","555");
        drHmm.setValue("age",28);
        drHmm.setValue("height",1.65);
        drHmm.setValue("height",1.65);
        drHmm.setValue("birthday","2000-09-01");

        dt.rows().add(new Object[]{5,"张三","123456",20,1.83,"2000-10-01"});
        dt.rows().add(new Object[]{6,"李四","123456",30,1.73,"2000-11-01"});
        dt.rows().add(new Object[]{7,"杜子腾","123456",35,1.82,"2000-12-01"});
        dt.rows().add(new Object[]{8,"史珍香","123456",19,1.68,"2000-03-01"});
        dt.rows().add(new Object[]{9,"小明","123456",10,0.9,"2015-03-01"});

        return dt;
    }
    // 查询int类型
    public static void main1(String[] args) {
        DataTable dt = ready();

//        DataTable result = dt.select("age", DataQuery.Option.lt, 26);


//        DataTable result = query.select()
//                .filter("age", DataQuery.Option.lte, 25)
//                .getResult();

//        DataTable result = query.select()
//                .filter("age", DataQuery.Option.gt, 28)
//                .getResult();
//        DataTable result = query.select()
//                .filter("age", DataQuery.Option.gte, 28)
//                .getResult();

//        DataTable result = query.select()
//                .filter("age", DataQuery.Option.eq, 20)
//                .getResult();

        DataRow[] result = dt.select("age", DataQuery.Option.neq, 20);
        Out.println("",result);
//        printColumns(result);
//        printDatas(result);
    }
    // 查询double类型
    public static void main(String[] args) {
        DataTable dt = ready();

//        DataTable result = dt.select("height", DataQuery.Option.lt, 1.68);


//        DataTable result = query.select()
//                .filter("height", DataQuery.Option.lte, 1.68)
//                .getResult();

//        DataTable result = query.select()
//                .filter("height", DataQuery.Option.gt, 1.83)
//                .getResult();

//        DataTable result = query.select()
//                .filter("height", DataQuery.Option.gte, 1.82)
//                .getResult();

//        DataTable result = query.select()
//                .filter("height", DataQuery.Option.eq, 1.82)
//                .getResult();

//        DataTable result = dt.select("height", DataQuery.Option.neq, 1.82);
        DataRow[] result = dt.select("height", DataQuery.Option.lt, 1);
        Out.println("",result);


//        printColumns(result);
//        printDatas(result);
    }
    // 查询字符串类型
    public static void main3(String[] args) {
        DataTable dt = ready();

//        DataTable result = query.selectAll()
//                .filter("username", DataQuery.Option.start, "韩")
//                .getResult();

//        DataTable result = query.selectAll()
//                .filter("username", DataQuery.Option.end, "i")
//                .getResult();

//        DataTable result = query.select()
//                .filter("username", DataQuery.Option.contain, "珍")
//                .getResult();
//        DataTable result = query.select()
//                .filter("username", DataQuery.Option.eq, "史珍香")
//                .getResult();
        DataRow[] result = dt.select("birthday",DataQuery.Option.neq,"2000-09-01");
//        DataTable result = dt.select("birthday",DataQuery.Option.lt,"2000-09-01");
//        DataTable result = dt.select("birthday",DataQuery.Option.lte,"2000-09-01");
//        DataTable result = dt.select("birthday",DataQuery.Option.gt,"2000-09-01");
//        DataTable result = dt.select("birthday",DataQuery.Option.gte,"2000-09-01");
        Out.println("",result);
//        printColumns(result);
//        printDatas(result);
    }
    static void printColumns(DataTable dt){
        Out.println("所有列、类型");
        for(int i = 0,size = dt.columns().count();i<size;i++){
            DataColumn item = dt.columns().get(i);
            Out.println(item.getName(),item.getType());
        }
    }

    static void printDatas(DataTable dt){
        Out.println("所有的数据：");
        for(int i = 0,size = dt.rows().count(); i<size ; i++){
            DataRow row = dt.rows().get(i);

            for(int j = 0,count = dt.columns().count();j<count;j++) {
                Out.print("", row.getValue(j),",");
            }
            Out.println();
        }
    }
}
